<?php
require_once "Topic_Builder.class.php";

// Process form submission (may not have occured -- method will sort it out)

//Donovan added crap to get the config from the server url
$SERVER_NAME = $_SERVER["SERVER_NAME"];
list($config_instance) = split("[/.]", $SERVER_NAME, 2);



$config = Topic_Builder::process_form_submission( $config_instance );


// DEBUG
$preview = ( $_GET[ 'preview' ] || $_POST[ 'sub_preview' ] );

$builder = new Topic_Builder( $config_instance , $config, $preview );

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<meta http-equiv="Content-Script-Type" content="text/javascript" />

<meta http-equiv="Content-Style-Type" content="text/css" />

<link rel="stylesheet" type="text/css" href="/media/topic_builder.css" media="all" />

<title>Daylife Topic Builder</title>

</head>


<body>

<div id="content">

<h1 id="topic_builder_heading">
Daylife Topic Pages Maker: Configurator
</h1>

<form id="topic_builder" method="post" action="<?php echo htmlspecialchars( $_SERVER[ 'PHP_SELF' ] ); ?>">

<fieldset id="fieldset_daylife_content">

<h1 class="fieldset_heading">
1. First, tell us what you want on your pages
</h1>

<div>

<span>
<?
$accesskey = (isset($_REQUEST['accesskey'])) ? $_REQUEST['accesskey'] : $builder->stored_config()->{ 'accesskey' }[0];
$sharedsecret = (isset($_REQUEST['sharedsecret'])) ? $_REQUEST['sharedsecret'] : $builder->stored_config()->{ 'sharedsecret' }[0];

?>
<span class="label">DayPI Access Key: </span>&nbsp;&nbsp;
<!--<input type="text" name="config[accesskey]" value="<?php echo $builder->stored_config()->{ 'accesskey' }[0]; ?>" size="60" class="control" />-->
<input type="text" name="config[accesskey]" value="<?php echo $accesskey; ?>" size="60" class="control" />

<br><br>
<span class="label">DayPI Shared Secret: </span>&nbsp;&nbsp;
<!--<input type="text" name="config[sharedsecret]" value="<?php echo $builder->stored_config()->{ 'sharedsecret' }[0]; ?>" size="60" class="control" />-->
<input type="text" name="config[sharedsecret]" value="<?php echo $sharedsecret; ?>" size="60" class="control" />

<br><br>

<input type="checkbox" name="config[components][images][enabled]" id="images_enabled" value="1" <?php echo (

  ( (string) $builder->stored_config()->{ 'components' }[0]->{ 'images' }[0]->{ 'enabled' }[0] ) ?

  'checked="checked"' :

  ""

); ?> />

<label for="images_enabled">Show</label>

</span>


<span>

<select name="config[components][images][limit]" id="images_limit">
<?php

$options = range( 1, 10 );

foreach ( $options as $o_label ) {

  $selected_attr = (

    ( (string) $o_label == (string) $builder->stored_config()->{ 'components' }[0]->{ 'images' }[0]->{ 'limit' }[0] ) ?

    'selected="selected"' :

    ""

  );

  echo <<<DOCHERE

<option value="{$o_label}" {$selected_attr}>{$o_label}</option>

DOCHERE;

}
// foreach

?>

</select>

<span>images</span>,

</span>


<span>

<span>sorted by</span>

<select name="config[components][images][sort]" id="images_sort">
<?php

$options = array( 'date' => "Date", 'relevance' => "Relevance" );

foreach ( $options as $o_ID => $o_label ) {

  $selected_attr = (

    ( $o_ID == (string) $builder->stored_config()->{ 'components' }[0]->{ 'images' }[0]->{ 'sort' }[0] ) ?

    'selected="selected"' :

    ""

  );

  echo <<<DOCHERE

<option value="{$o_ID}" {$selected_attr}>{$o_label}</option>

DOCHERE;

}
// foreach

?>

</select>

&nbsp; using a source filter id &nbsp;
<input type="text" name="config[components][images][source_filter_id]" value="<?php echo $builder->stored_config()->{ 'components' }[0]->{ 'images' }[0]->{ 'source_filter_id' }[0]; ?>" size="60" class="control" />

</span>

</div>

<!--
<div>

<span>

<input type="checkbox" name="config[components][articles][enabled]" id="articles_enabled" value="1" <?php echo (

  ( (string) $builder->stored_config()->{ 'components' }[0]->{ 'articles' }[0]->{ 'enabled' }[0] ) ?

  'checked="checked"' :

  ""

); ?> />

<label for="articles_enabled">Show</label>

</span>


<span>

<select name="config[components][articles][limit]" id="articles_limit">
<?php

$options = range( 1, 10 );

foreach ( $options as $o_label ) {

  $selected_attr = (

    ( (string) $o_label == (string) $builder->stored_config()->{ 'components' }[0]->{ 'articles' }[0]->{ 'limit' }[0] ) ?

    'selected="selected"' :

    ""

  );

  echo <<<DOCHERE

<option value="{$o_label}" {$selected_attr}>{$o_label}</option>

DOCHERE;

}
// foreach

?>

</select>

<span>articles</span>,

as they come off the wire

</span>

</div>

-->
<div>

<span>

<input type="checkbox" name="config[components][stories][enabled]" id="stories_enabled" value="1" <?php echo (

  ( (string) $builder->stored_config()->{ 'components' }[0]->{ 'stories' }[0]->{ 'enabled' }[0] ) ?

  'checked="checked"' :

  ""

); ?> />

<label for="stories_enabled">Show</label>

</span>


<span>

<select name="config[components][stories][limit]" id="stories_limit">
<?php

$options = range( 1, 10 );

foreach ( $options as $o_label ) {

  $selected_attr = (

    ( (string) $o_label == (string) $builder->stored_config()->{ 'components' }[0]->{ 'stories' }[0]->{ 'limit' }[0] ) ?

    'selected="selected"' :

    ""

  );

  echo <<<DOCHERE

<option value="{$o_label}" {$selected_attr}>{$o_label}</option>

DOCHERE;

}
// foreach

?>

</select>

<span>of the biggest stories</span>

</span>


<span>

<span>from the past</span>,

<select name="config[components][stories][term]" id="stories_term">
<?php

$options = array( 'day' => "Day", 'week' => "Week", 'month' => "Month" );

foreach ( $options as $o_ID => $o_label ) {

  $selected_attr = (

    ( $o_ID == (string) $builder->stored_config()->{ 'components' }[0]->{ 'stories' }[0]->{ 'term' }[0] ) ?

    'selected="selected"' :

    ""

  );

  echo <<<DOCHERE

<option value="{$o_ID}" {$selected_attr}>{$o_label}</option>

DOCHERE;

}
// foreach

?>

</select>

</span>


<span>

<span>sorted by</span>

<select name="config[components][stories][sort]" id="stories_sort">
<?php

$options = array( 'date' => "Date", 'relevance' => "Relevance" );

foreach ( $options as $o_ID => $o_label ) {

  $selected_attr = (

    ( $o_ID == (string) $builder->stored_config()->{ 'components' }[0]->{ 'stories' }[0]->{ 'sort' }[0] ) ?

    'selected="selected"' :

    ""

  );

  echo <<<DOCHERE

<option value="{$o_ID}" {$selected_attr}>{$o_label}</option>

DOCHERE;

}
// foreach

?>

</select>

</span>

</div>


<div>

<span>

<input type="checkbox" name="config[components][quotes][enabled]" id="quotes_enabled" value="1" <?php echo (

  ( (string) $builder->stored_config()->{ 'components' }[0]->{ 'quotes' }[0]->{ 'enabled' }[0] ) ?

  'checked="checked"' :

  ""

); ?> />

<label for="quotes_enabled">Show</label>

</span>


<span>

<select name="config[components][quotes][limit]" id="quotes_limit">
<?php

$options = range( 1, 5 );

foreach ( $options as $o_label ) {

  $selected_attr = (

    ( (string) $o_label == (string) $builder->stored_config()->{ 'components' }[0]->{ 'quotes' }[0]->{ 'limit' }[0] ) ?

    'selected="selected"' :

    ""

  );

  echo <<<DOCHERE

<option value="{$o_label}" {$selected_attr}>{$o_label}</option>

DOCHERE;

}
// foreach

?>

</select>

<span>quotes</span>

</span>

</div>

<!--
<div>

<span>

<input type="checkbox" name="config[components][timeline][enabled]" id="timeline_enabled" value="1" <?php echo (

  ( (string) $builder->stored_config()->{ 'components' }[0]->{ 'timeline' }[0]->{ 'enabled' }[0] ) ?

  'checked="checked"' :

  ""

); ?> />

<span><label for="timeline_enabled">Show</label> a timeline of news from the last 30 days.</span>

</span>

</div>
-->

<div>

<span>

<input type="checkbox" name="config[components][connections][enabled]" id="connections_enabled" value="1" <?php echo (

  ( (string) $builder->stored_config()->{ 'components' }[0]->{ 'connections' }[0]->{ 'enabled' }[0] ) ?

  'checked="checked"' :

  ""

); ?> />

<label for="connections_enabled">Show</label>

</span>


<span>

<select name="config[components][connections][limit]" id="connections_limit">
<?php

$options = range( 1, 10 );

foreach ( $options as $o_label ) {

  $selected_attr = (

    ( (string) $o_label == (string) $builder->stored_config()->{ 'components' }[0]->{ 'connections' }[0]->{ 'limit' }[0] ) ?

    'selected="selected"' :

    ""

  );

  echo <<<DOCHERE

<option value="{$o_label}" {$selected_attr}>{$o_label}</option>

DOCHERE;

}
// foreach

?>

</select>

<span>people and organizations related to your topic.</span>

</span>

</div>

</fieldset>
<!-- #fieldset_daylife_content -->


<fieldset id="fieldset_style">

<h1 class="fieldset_heading">
2. Choose a style for your pages.
</h1>

<div id="canned_styles">

<span>Pick a canned style:</span>

<span>

<input type="radio" name="config[canned_style][]" id="canned_style_1" value="1" <?php echo (

  ( "1" == (string) $builder->stored_config()->{ 'canned_style' }[0]->{ 'id' }[0] ) ?

  'checked="checked"' :

  ""

); ?> />

<label for="canned_style_1"><img src="images/style_thumb.gif" width="66" height="66" alt="" /></label>

</span>


<span>

<input type="radio" name="config[canned_style][]" id="canned_style_2" value="2" <?php echo (

  ( "2" == (string) $builder->stored_config()->{ 'canned_style' }[0]->{ 'id' }[0] ) ?

  'checked="checked"' :

  ""

); ?> />

<label for="canned_style_2"><img src="images/style_thumb.gif" width="66" height="66" alt="" /></label>

</span>


<span>

<input type="radio" name="config[canned_style][]" id="canned_style_3" value="3" <?php echo (

  ( "3" == (string) $builder->stored_config()->{ 'canned_style' }[0]->{ 'id' }[0] ) ?

  'checked="checked"' :

  ""

); ?> />

<label for="canned_style_3"><img src="images/style_thumb.gif" width="66" height="66" alt="" /></label>

</span>

</div>


<div>

<input type="radio" name="config[canned_style][]" value="custom" <?php echo (

  ( "custom" == (string) $builder->stored_config()->{ 'canned_style' }[0]->{ 'id' }[0] ) ?

  'checked="checked"' :

  ""

); ?> />

<span>Or give us a URL to your own css: </span>

<input type="text" name="config[css_includes][css_urls][]" value="<?php echo htmlspecialchars( (string) $builder->stored_config()->{ 'css_includes' }[0]->{ 'css_url' }[0] ); ?>" size="60" />

</div>

</fieldset>
<!-- #fieldset_style -->


<fieldset id="fieldset_custom_content">

<h1 class="fieldset_heading">
3. Customize the header and footer of your page.
</h1>

<div>

<label for="header_html">Custom header html</label>

<textarea name="config[header_html]" id="header_html" rows="6" cols="60"><?php echo htmlspecialchars( (string) $builder->stored_config()->{ 'header_html' }[0] ); ?></textarea>

</div>


<div>

<label for="footer_html">Custom footer html</label>

<textarea name="config[footer_html]" id="footer_html" rows="6" cols="60"><?php echo htmlspecialchars( (string) $builder->stored_config()->{ 'footer_html' }[0] ); ?></textarea>

</div>

</fieldset>
<!-- #fieldset_custom_content -->


<div class="buttons">

<input type="submit" value="Preview your changes below" name="sub_preview" />

<input type="submit" value="Save Your Changes" name="sub_save" />

<input type="submit" value="Cancel Changes" name="sub_cancel" />

</div>
<!-- .buttons -->

</form>
<!-- #topic_builder -->


<?php

if ( $_POST[ 'sub_preview' ] ) {

?>


<div id="preview">

<h1>
Preview your page
</h1>


<iframe src="<?php echo htmlspecialchars( $_SERVER[ 'PHP_SELF' ] ) . "?user_ID={$_GET[ 'user_ID' ]}&amp;preview=1"; ?>"></iframe>

</div>
<!-- #preview -->

<?php

}
// if

?>


</div>
<!-- #content -->

</body>

</html>
